/**
  ******************************************************************************
  * @file    debug.c
  * @author  Garen
  * @version V1.0.0
  * @date    2018-09-28
  * @brief   系统函数入口  
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include "debug.h"
/* extern variables ----------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
static int debug_level = DEBUG_ERROR; // 调试打印信息输出等级
/* Private functions ---------------------------------------------------------*/

/**		  
 * @brief print_usage()运行参数提示
 * @param[in] name 
 * @return void 
 */
static void print_usage(char *name)
{
    printf("\nUsage:\n\n"
           "  %s [option] [parameter]\n\n"
           "  Options:\n"
           "    -debug level #set debug print level: 0-DEBUG_NONE 1-DEBUG_ERROR 2-DEBUG_WARN 3-DEBUG_NOTICE 4-DEBUG_INFO"
           "\n\n",
           name);
    return;
}

/**		  
 * @brief 获取调试打印信息输出等级
 * @param 无
 * @return 调试打印信息输出等级
 */
int get_debug_level(void)
{
    return debug_level;
}

/**		  
 * @brief		设置调试打印信息输出等级 
 * @param[in] level 调试打印信息输出等级
 * @return 无
 */
void set_debug_level(int level)
{
    debug_level = level;
}

/**		  
 * @brief  配置系统打印 
 * @return 无
 */
void config_debug(int argc, char *argv[])
{
    /*设置打印级别*/
    for (int i = 1; i < argc; i++)
    {
        if (strcmp(argv[i], "-debug") == 0)
        {
            i++;
            if (i >= argc)
            {
                print_usage(argv[0]);
                exit(1);
            }
            set_debug_level(atoi(argv[i]));
        }
    }
}

/************************ (C) COPYRIGHT END OF FILE **************************/
